package handlers

import (
	"encoding/json"
	"goserver/models"
	"goserver/utils"
	"net/http"
)

type PersonHandler struct {
	*BaseHandler[models.Person]
}

func NewPersonHandler(repo *models.PersonRepository) *PersonHandler {
	return &PersonHandler{
		BaseHandler: NewBaseHandler(repo.BaseRepository),
	}
}

func (h *PersonHandler) AddPerson(w http.ResponseWriter, r *http.Request) {
	var Person models.Person
	if r.Method == http.MethodPost {
		err := json.NewDecoder(r.Body).Decode(&Person)
		if err != nil {
			utils.Response(w, http.StatusBadRequest, "JSON解析失败: "+err.Error(), nil) // 响应 Bad Reques
			return
		}
	}
	h.AddEntity(w, r, Person, "")
}
